package com.tcm.day06;

/**
 * 对称二叉树
 * https://leetcode.cn/problems/symmetric-tree/description/?envType=problem-list-v2&envId=binary-tree
 */
public class Code03_MirrorTree {
    public boolean isSymmetric(TreeNode root) {
        return isMirrorTree(root, root);
    }

    public boolean isMirrorTree(TreeNode node1, TreeNode node2) {
        if (node1 == null ^ node2 == null) {
            return false;
        }
        if (node1 == null && node2 == null) {
            return true;
        }

        return node1.val == node2.val && isMirrorTree(node1.left, node2.right) && isMirrorTree(node1.right, node2.left);
    }
}
